package com.summo.demo.config.aspect;

import javax.servlet.http.HttpServletRequest;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice(basePackages = {"com.summo.demo"})
public class GlobalBizExceptionHandler {

    @ExceptionHandler(value = {Throwable.class})
    ResponseEntity handleException(Throwable e, HttpServletRequest request) {
        //处理RuntimeException异常
        if (e instanceof RuntimeException) {
            return ResponseEntity.ok(e.getMessage());
        }
        return ResponseEntity.ok("系统开小差了");
    }
}
